<?php
namespace Admin\Controller\Work;
use Think\Page;
use Admin\Controller\AdminController;
class VistaController extends AdminController
{
	  public function index()
	  {
	  $count = M("saleman_sign")->where("1=1")->count();
	  $page = new Page($count,10);
      $show = $page->show();
	  $result = M("saleman_sign")->join("ymt_saleman on ymt_saleman_sign.saleman_id=ymt_saleman.id")->limit($page->firstRow.','.$page->listRows)->field("ymt_saleman_sign.clinic_name,ymt_saleman_sign.sign_time,ymt_saleman.real_name,ymt_saleman_sign.id")->select();
	 $this->assign("result",$result);
	 $this->assign("page",$show);
	 $this->assign("count",$count);
	 $this->display();
	  }
       public function anp()
	 {
	 	   $where = "";
	 	   if(isset($_GET['search']) && !empty($_GET['search']))
	 	   {
	 	   	  $where.="real_name='".$_GET['search']."' and ";
	 	   }
	 	   $where.=" role_id=1";
	 	   $count = M("saleman")->where($where)->join("ymt_saleman_trip on ymt_saleman_trip.saleman_id=ymt_saleman.id")->count();
	 	   $page = new Page($count,20);
	 	   $show = $page->show();
	 	   $lists = M("saleman")->where($where)->join("ymt_saleman_trip on ymt_saleman_trip.saleman_id=ymt_saleman.id")->limit($page->firstRow.','.$page->listRows)->select();

           $this->assign("_list",$lists);
           $this->assign("page",$show);
	 	   $this->display();
	 }
	  public function delete()
	  {
	  	  $id = $_GET['id'];
	  	  $flag = M("saleman_sign")->where("id=".$id)->delete();
	  	  if($flag)
	  	  {
	  	  	  $this->ajaxReturn(array('code'=>1,'message'=>'删除成功'));
	  	  	  return;
	  	  }
	  	  $this->ajaxReturn(array('code'=>0,'message'=>'删除失败'));
	  }
	  public function add()
	  {
	  	   if(!IS_AJAX)
	  	   {
	  	   	     if(isset($_GET['type']) && $_GET['type']=='edit')
	  	   	     {
	  	   	     	  $res = M("saleman_sign")->where("id=".$_GET['id'])->find();

	  	   	     	  $clinic_res = M("clinic")->where("1=1")->select();
	  	   	     	  $sale = M("saleman")->where("1=1")->select();
	  	   	     	  $this->assign("clinic_res",$clinic_res);
	  	   	     	  $this->assign("sale",$sale);
	  	   	     	  $this->assign("res",$res);

	  	   	     }
	  	   	     $this->display();
	  	   }else{
	  	   	  if(isset($_GET['id']) && !empty($_GET['id']))
	  	   	  {
	  	   	  	   $ret = strtotime($_POST['sign_time']);
	  	   	  	   if(date('Y-m-d H:i:s',strtotime($_POST['sign_time']))!==$_POST['sign_time'])
	  	   	  	   {
	  	   	  	   	   $this->ajaxReturn(array('code'=>0,'message'=>'请填写正确的格式'));
	  	   	  	   	   return;
	  	   	  	   }
	  	   	  	   $_POST['sign_date'] = explode(' ' ,$_POST['sign_time'])[0];
	  	   	  	   $_POST['sign_time'] = strtotime($_POST['sign_time']);
	  	   	  	   $_POST['clinic_name'] = M("clinic")->where("id=".$_POST['clinic_id'])->getField("clinic_name");
	  	   	  	   $flag = M("saleman_sign")->where("id=".$_GET['id'])->save($_POST);
	  	   	  	   if($flag)
	  	   	  	   {
	  	   	  	   	  $this->ajaxReturn(array('code'=>1,'message'=>'操作成功'));
	  	   	  	   	  return;
	  	   	  	   }
	  	   	  	   $this->ajaxReturn(array('code'=>1,'message'=>'操作失败'));
	  	   	  }
	  	   }
	  }
}

?>